<template>
  <div class="todo-footer">
    <label>
      <input type="checkbox" v-model="isChecked"/>
    </label>
    <span>
          <span>已完成{{selected}}</span> / 全部{{todos.length}}
        </span>
    <button class="btn btn-danger" @click="deleteAllSelectedTodo">清除已完成任务</button>
  </div>
</template>

<script>
export default {
  name: "Footer",
  props:['todos','changeAllTodoChecked','deleteAllSelectedTodo'],
  computed:{
    selected() {
      return this.todos.reduce((pre,cur)=>cur.done? pre+1:pre,0)
    },
    isChecked:{
      get(){
        return this.selected === this.todos.length && this.todos.length
      },
      set(newVal){
        this.changeAllTodoChecked(newVal)
      }
    }
  }
}
</script>

<style scoped>
@import url('@/assets/css/Footer.css');
</style>